package com.china.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.china.osourcechina.R;
import com.china.vo.SelectBean;

import java.util.List;

/**
 * Created by 孙肖雪 on 2016/5/12.
 */
public class SelectGridAdapter extends BaseAdapter{
    private List<SelectBean> ls;
    private Context context;

    public SelectGridAdapter(List<SelectBean> ls, Context context) {
        super();
        this.ls = ls;
        this.context = context;
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return ls.size();
    }

    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    public View getView(int arg0, View arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
        ViewHolder holder=null;
        if (arg1==null) {
            holder=new ViewHolder();
            arg1= LayoutInflater.from(context).inflate(R.layout.item_selectgrid, null);
            holder.selectgrid_image=(ImageView) arg1.findViewById(R.id.selectgrid_image);
            holder.selectgrid_text=(TextView) arg1.findViewById(R.id.selectgrid_text);
            arg1.setTag(holder);
        }else{
            holder=(ViewHolder) arg1.getTag();
        }

        holder.selectgrid_image.setImageResource(ls.get(arg0).getImage());
        holder.selectgrid_text.setText(ls.get(arg0).getName());
        return arg1;
    }

    class ViewHolder{
        ImageView selectgrid_image;
        TextView selectgrid_text;
    }
}
